<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  
  <meta name="generator" content="Hugo 0.98.0" />

  
  <meta name="description" content="走在通往幸福的路上">
  

  
  <link rel="apple-touch-icon" sizes="180x180" href="https://blog.v5u.win/apple-touch-icon.png">

  
  <link rel="icon" type="image/png" sizes="32x32" href="https://blog.v5u.win/favicon-32x32.png">

  
  <link rel="icon" type="image/png" sizes="16x16" href="https://blog.v5u.win/favicon-16x16.png">

  
  <link rel="manifest" href="https://blog.v5u.win/site.webmanifest">

  
  <link rel="mask-icon" href="https://blog.v5u.win/safari-pinned-tab.svg" color="">

  <meta name="msapplication-TileColor" content="">

  <meta name="theme-color" content="">

  
  <link rel="stylesheet" href="https://blog.v5u.win/css/bootstrap.min.css" />

  
  <title>Docker Etcd | 为吾优</title>
  

  <style>
body {
  min-width: 300px;
}

.custom-navbar {
  margin-bottom: 1em;
  height: 60px;
}

.custom-navbar a {
  display: inline-block; 
  padding: 18px 0;
  margin-right: 1em; 
  font-weight: bold; 
}

.custom-navbar a:hover,
.custom-navbar a:focus {
  text-decoration: none; 
}

@media print {
  .custom-navbar {
    display: none;
  }
}

article {
  padding-bottom: 1em;
}

img {
  max-width: 100%;
}


body {
  background-color: #fff;
}



body {
  color: #212529;
}



a {
  color: #007bff;
}



a:hover,
a:focus {
  color: #0056b3;
}



.custom-navbar {
  background-color: #212529;
}



.custom-navbar a {
  color: rgba(255,255,255,.75);
}



.custom-navbar a:hover,
.custom-navbar a:focus {
  color: rgba(255,255,255,1);
}



.container {
  max-width: 800px;
}





</style>
</head>

<body>
  <nav class="custom-navbar">
  <div class="container">
    
    <a href="/">文章</a>
    
    <a href="/tags/">标签</a>
    
    <a href="/about/">关于</a>
    
    <a href="/index.xml">RSS</a>
    
  </div>
</nav>
  
  <div class="container">
    <article>
      <h1>Docker Etcd</h1>
<p>[TOC]</p>
<h3 id="描述">描述</h3>
<p>etcd是CoreOS团队于2013年6月发起的开源项目，它的目标是构建一个高可用的分布式键值(key-value)数据库。etcd内部采用raft协议作为一致性算法，etcd基于Go语言实现。</p>
<p>etcd作为服务发现系统，有以下的特点</p>
<ul>
<li>简单：安装配置简单，而且提供了HTTP API进行交互，使用也很简单</li>
<li>安全：支持SSL证书验证</li>
<li>快速：根据官方提供的benchmark数据，单实例支持每秒2k+读操作</li>
<li>可靠：采用raft算法，实现分布式系统数据的可用性和一致性</li>
<li>etcd项目地址：https://github.com/coreos/etcd/</li>
</ul>
<h3 id="下载">下载</h3>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sh" data-lang="sh"><span style="display:flex;"><span>$ docker search etcd
</span></span><span style="display:flex;"><span>$ docker pull xxx/etcd
</span></span></code></pre></div><h2 id="etcd参数说明">ETCD参数说明</h2>
<ul>
<li>**data-dir:**指定节点的数据存储目录，这些数据包括节点ID，集群ID，集群初始化配置，Snapshot文件，若未指定—wal-dir，还会存储WAL文件；</li>
<li>**wal-dir:**指定节点的was文件的存储目录，若指定了该参数，wal文件会和其他数据文件分开存储。</li>
<li><strong>name:</strong> 节点名称</li>
<li><strong>initial-advertise-peer-urls:</strong> 告知集群其他节点url.(<code>对于集群内提供服务的url</code>)</li>
<li><strong>listen-peer-urls:</strong> 监听URL，用于与其他节点通讯</li>
<li><strong>advertise-client-urls:</strong> 告知客户端url, 也就是服务的url(<code>对外提供服务的utl</code>)</li>
<li><strong>initial-cluster-token:</strong> 集群的ID</li>
<li><strong>initial-cluster:</strong> 集群中所有节点</li>
</ul>
<p>然后进入其中一个 Docker 主机：</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sh" data-lang="sh"><span style="display:flex;"><span>$ docker exec -it etcd bin/sh
</span></span></code></pre></div><p>执行下面命令（查看集群成员）：</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sh" data-lang="sh"><span style="display:flex;"><span>$ etcdctl member list
</span></span></code></pre></div>
    </article>
  </div>

  
  
  

  
</body>

</html>